var $ = getApp(), methods = require("../methods.js");
Page(Object.assign({}, methods, {
	data: {
		id: 0,
		pageinfo: [],
		pagecontent: [],
		hideguanggao:0,
	},
	_onLoad: function () {
		var that = this
		var id = 0;
    if (that.options && that.options.id) {
			id = that.options.id
			that.setData({ id: id})
		}
		if (that.options && that.options.scene) {
			var scenes = that.options.scene.split('_');
			if(scenes[1]){
				id = parseInt(scenes[1]);
				that.setData({ id: id});
			}
		}
		$.post('index/main', { id: id }, function (data) {
			if(data.status == 2){//付费查看
				$.goto('/pages/wxpay/pagepay?fromPage=main&orderid='+data.orderid+'&pageid='+id,'redirect');
				return;
			}
			if (data.status == 1) {
				var pageinfo = data.pageinfo
				var pagecontent = data.pagecontent
				var _bannerindex = [];
				for(var i in pagecontent){
					_bannerindex[i] = 0;
				}
				data.sysset.textset = that.data.textset
				that.setData({ title: data.pageinfo.title,sysset: data.sysset,guanggaopic:data.guanggaopic,guanggaourl:data.guanggaourl,pageinfo: data.pageinfo, pagecontent: pagecontent,_bannerindex:_bannerindex})
				wx.setNavigationBarTitle({ title: data.pageinfo.title })
			} else {
				if(data.msg){
					$.alert(data.msg,function(){
						if(data.url) $.goto(data.url)
					});
				}else if(data.url){
					$.goto(data.url)
				}else{
					$.alert('您无查看权限');
				}
			}
		})
	},
	closegg:function(){
		this.setData({hideguanggao:1})
	}
}));